Requires Scripting PRO
The SSHClient class provides an interface for connecting to a remote SSH server, executing commands, opening TTY or PTY sessions, transferring files via SFTP, and performing multi-hop SSH jumps. It supports both command-based and interactive terminal-based workflows.
This class is central to establishing and managing SSH sessions in your script.
SSHClient.connect(options): Promise<SSHClient>Establishes a connection to a remote SSH server.
options (object):
host (string):
The hostname or IP address of the SSH server.
port? (number):
The port number to connect to. Defaults to 22.
authenticationMethod (SSHAuthenticationMethod):
The authentication method to use (e.g., password, RSA key).
trustedHostKeys? (string[]):
Optional list of trusted server public keys. If provided, the client will validate the server against this list.
reconnect? ("never" | "once" | "always"):
Optional strategy for reconnecting if the connection drops. Default is "never".
Promise that resolves to an SSHClient instance upon successful connection.onDisconnect: (() => void) | nullCallback function to be invoked when the SSH connection is lost or closed.
executeCommand(command: string, options?): Promise<string>Executes a shell command on the remote server and returns its output.
command (string):
The command to execute.
options? (object):
maxResponseSize? (number):
Maximum number of bytes to return.
includeStderr? (boolean):
If true, includes standard error output in the result.
inShell? (boolean):
If true, executes the command inside a shell (e.g., sh -c). Default is false.
Promise that resolves to the command output as a string.executeCommandStream(command, onOutput, options?): Promise<void>Executes a command and streams its output line-by-line.
command (string):
The command to run.
onOutput (function):
Callback (text: string, isStderr: boolean) => boolean
Called for each line of output. Return false to stop receiving output.
options?:
inShell? (boolean):
Whether to run the command in a shell.Promise that resolves when the command completes.withPTY(options): Promise<TTYStdinWriter>Opens a PTY (pseudo-terminal) session.
options (object):
wantReply? (boolean):
Whether to wait for a reply from the server. Defaults to true.
term? (string):
Terminal type (default is "xterm").
terminalCharacterWidth? (number):
Terminal character width. Default is 80.
terminalRowHeight? (number):
Terminal row height. Default is 24.
terminalPixelWidth? (number):
Terminal pixel width. Default is 0.
terminalPixelHeight? (number):
Terminal pixel height. Default is 0.
onOutput (function):
Callback (text: string, isStderr: boolean) => boolean for receiving terminal output.
onError? (function):
Optional error callback (error: string) => void.
Promise that resolves to a TTYStdinWriter instance.withTTY(options): Promise<TTYStdinWriter>Opens a TTY session with simplified options (without explicit dimensions).
options (object):
onOutput (function):
Callback for each line of output.
onError? (function):
Callback for error reporting.
Promise that resolves to a TTYStdinWriter.openSFTP(): Promise<SFTPClient>Opens an SFTP session for file transfer operations.
Promise that resolves to an SFTPClient instance.jump(options): Promise<SSHClient>Performs an SSH jump (proxy) to another remote host from the current SSH session.
options (object):
host (string):
The destination host to jump to.
port? (number):
Port to connect to (default is 22).
authenticationMethod (SSHAuthenticationMethod):
Authentication method for the next host.
trustedHostKeys? (string[]):
Optional list of trusted host keys.
Promise that resolves to a new SSHClient representing the jump connection.close(): Promise<void>Closes the SSH connection and releases associated resources.
Important: You should call this method when the SSH client is no longer needed to avoid potential memory or socket leaks.
Promise that resolves when the SSH connection is successfully closed.